package pl.matt.model;

import java.util.Collection;
import java.util.HashSet;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name="frame_regions")
public class FrameRegion extends AbstractEntity {

	@ManyToOne(optional=false)
	@JoinColumn(name="frame_id")
	private Frame frame;

	@Embedded
	private Rectangle rectangle = new Rectangle();
	
	@Column(name="frame_region_type")
	@Enumerated(EnumType.STRING)
	private FrameRegionType frameRegionType;
	
	@Column(nullable=false)
	private boolean artificial = false;
	
	/**
	 * czy zweryfikowany, 
	 * powinien być tylko jeden pozytywnie zweryfikowany rezultat
	 * o określonym typie dla danej klatki
	 */
	private boolean verified;
	
	public FrameRegion() {
		
	}
	
	public FrameRegion(long id, Frame frame, int x, int y, int width, int height, FrameRegionType frameRegionType,
			boolean verified) {
		super();
		setId(id);
		this.frame = frame;
		this.rectangle = new Rectangle(x, y, width, height);
		this.frameRegionType = frameRegionType;
		this.verified = verified;
		Collection<FrameRegion> regions = frame.getFrameRegions();
		if (regions == null) {
			regions = new HashSet<FrameRegion>();
			frame.setFrameRegions(regions);
		}
		regions.add(this);
	}
	public Frame getFrame() {
		return frame;
	}
	public void setFrame(Frame frame) {
		this.frame = frame;
	}
	public int getX() {
		return rectangle.getX();
	}
	public void setX(int x) {
		rectangle.setX(x);
	}
	public int getY() {
		return rectangle.getY();
	}
	public void setY(int y) {
		this.rectangle.setY(y);
	}
	public int getWidth() {
		return rectangle.getWidth();
	}
	public void setWidth(int width) {
		rectangle.setWidth(width);
	}
	public int getHeight() {
		return rectangle.getHeight();
	}
	public void setHeight(int height) {
		rectangle.setHeight(height);
	}
	public boolean isVerified() {
		return verified;
	}
	public void setVerified(boolean verified) {
		this.verified = verified;
	}
	public FrameRegionType getFrameRegionType() {
		return frameRegionType;
	}
	public void setFrameRegionType(FrameRegionType frameRegionType) {
		this.frameRegionType = frameRegionType;
	}

	public boolean isArtificial() {
		return artificial;
	}

	public void setArtificial(boolean artificial) {
		this.artificial = artificial;
	}

	public Rectangle getRectangle() {
		return rectangle;
	}

	public void setRectangle(Rectangle rectangle) {
		this.rectangle = rectangle;
	}
	
}
